<template>
  <div class="latest-news-section">
    <div class="section-header">
      <h2 class="section-title">
        <i class="icon-new">🆕</i> 最新动态
      </h2>
      <el-tag type="primary">实时更新</el-tag>
    </div>
    
    <div class="latest-news-list">
      <div 
        v-for="(item, index) in latestNews" 
        :key="item.id"
        class="latest-news-item"
        @click="openNews(item.url)"
      >
        <div class="item-index">{{ index + 1 }}</div>
        <div class="item-content">
          <h3 class="title">{{ item.title }}</h3>
          <div class="meta">
            <span class="source">{{ item.source }}</span>
            <span class="time">{{ item.time }}</span>
          </div>
        </div>
        <div class="item-image" :style="{ backgroundImage: `url(${item.image})` }"></div>
      </div>
    </div>
  </div>
</template>

<script setup>
import { defineProps } from 'vue';

defineProps({
  latestNews: {
    type: Array,
    required: true
  }
});

const openNews = (url) => {
  window.open(url, '_blank');
};
</script>

<style scoped>
.latest-news-section {
  background: linear-gradient(to right, #f0f7ff, #fff);
  border-radius: 16px;
  padding: 20px;
  margin-bottom: 30px;
  box-shadow: 0 6px 16px rgba(64, 158, 255, 0.1);
}

.section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}

.section-title {
  margin: 0;
  font-size: 24px;
  color: #409EFF;
  display: flex;
  align-items: center;
  font-weight: bold;
}

.icon-new {
  margin-right: 10px;
  font-size: 28px;
}

.latest-news-list {
  display: flex;
  flex-direction: column;
  gap: 15px;
}

.latest-news-item {
  display: flex;
  padding: 15px;
  background: white;
  border-radius: 12px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
  cursor: pointer;
  transition: all 0.3s;
  gap: 15px;
  align-items: center;
}

.latest-news-item:hover {
  transform: translateX(5px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.item-index {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: #f0f7ff;
  color: #409EFF;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: bold;
  flex-shrink: 0;
  font-size: 16px;
}

.item-content {
  flex: 1;
}

.title {
  margin: 0 0 8px 0;
  font-size: 15px;
  line-height: 1.4;
  font-weight: 600;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.meta {
  display: flex;
  gap: 15px;
  font-size: 12px;
  color: #666;
}

.source {
  color: #409EFF;
  font-weight: 500;
}

.item-image {
  width: 80px;
  height: 60px;
  border-radius: 8px;
  background-size: cover;
  background-position: center;
  flex-shrink: 0;
}

@media (max-width: 768px) {
  .latest-news-item {
    padding: 12px;
  }
  
  .item-image {
    width: 70px;
    height: 50px;
  }
  
  .section-title {
    font-size: 20px;
  }
}
</style>